package com.hmall.user.controller;


import com.hmall.common.utils.BeanUtils;
import com.hmall.user.domain.po.User;
import com.hmall.user.service.IAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


@Api(tags = "用户管理相关接口")
@RestController
@RequestMapping("/admin")
@RequiredArgsConstructor
public class AdminController {

    private final IAdminService IAdminService;

    @ApiOperation("根据id查询用户")
    @GetMapping("{id}")
    public User queryItemById(@PathVariable("id") Long id) {
        return BeanUtils.copyBean(IAdminService.getById(id), User.class);
    }

    @ApiOperation("新增用户")
    @PostMapping
    public void saveUser(@RequestBody User user) {
        IAdminService.save(BeanUtils.copyBean(user, User.class));
    }

    @ApiOperation("更新用户")
    @PutMapping
    public void updateUser(@RequestBody User user){
        IAdminService.updateById(BeanUtils.copyBean(user, User.class));
    }

    @ApiOperation("根据id删除用户")
    @DeleteMapping("{id}")
    public void deleteUserById(@PathVariable("id") Long id){
        IAdminService.removeById(id);
    }

}
